/**
 * 2015-12-19
 * StudentServiceImpl.java
 * author:sherlochao
 */
package com.sherlochao.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.sherlochao.beans.StudentBean;
import com.sherlochao.dao.StudentDao;
import com.sherlochao.model.Course;
import com.sherlochao.model.Student;
import com.sherlochao.model.StudyCourse;
import com.sherlochao.model.Teacher;
import com.sherlochao.service.StudentService;

/**
 * @author yinchao
 * 
 */
@Transactional
@Service("studentService")
public class StudentServiceImpl implements StudentService {

	@Resource
	private StudentDao studentDao;

	@Override
	public Student get(String id) {
		// TODO Auto-generated method stub
		return studentDao.get(id);
	}

	@Override
	public String save(Student entity) {
		// TODO Auto-generated method stub
		return studentDao.save(entity);
	}

	@Override
	public void delete(String id) {
		// TODO Auto-generated method stub
		studentDao.delete(id);
	}

	@Override
	public List<Student> findAllStudentByTeacherId(String teacherId) {
		// TODO Auto-generated method stub
		return studentDao.findAllStudentByTeacherId(teacherId);
	}

	@Override
	public List<StudyCourse> listStudyCourseByStudentId(String studentId) {
		return studentDao.listStudyCourseByStudentId(studentId);
	}

	@Override
	public List<Course> listCourseByStudentId(String studentId) {
		return studentDao.listCourseByStudentId(studentId);
	}

	@Override
	public List<Teacher> listTeacherNameByStudentId(String studentId) {
		return studentDao.listTeacherNameByStudentId(studentId);
	}

	@Resource
	private StudentService studentService;
	
	@Override
	public String test(String studentId) {
		StudentBean studentBean = new StudentBean();
		Student student = studentService.get(studentId);
		studentBean.setStudentId(student.getStudentId());
		studentBean.setStudentName(student.getStudentName());
		studentBean.setStudentBirthdate(student.getStudentBirthdate());
		List<StudyCourse> studyCourses = studentService
				.listStudyCourseByStudentId(studentId);
		studentBean.setCount(studyCourses.size());// 所选课程总数
		studentBean.setScores(studyCourses);// 所选课程的信息 成绩
		List<Course> courses = studentService.listCourseByStudentId(studentId);
		studentBean.setCourses(courses);
		List<Teacher> teachers = studentService
				.listTeacherNameByStudentId(studentId);
		studentBean.setTeachers(teachers);
		String json = JSON.toJSONString(studentBean);
		return json;

	}

}
